<?php

/**
 * TbsIpSalida filter form base class.
 *
 * @package    AltargetEcommerce
 * @subpackage filter
 * @author     Carlo Lopez
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseTbsIpSalidaFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'ipsa_ip'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'ipsa_nombre'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'ipsa_promcont'            => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'ipsa_status'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'ipsa_regonline'           => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'entregas_myaltarget_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'EntregaMyaltarget')),
    ));

    $this->setValidators(array(
      'ipsa_ip'                  => new sfValidatorPass(array('required' => false)),
      'ipsa_nombre'              => new sfValidatorPass(array('required' => false)),
      'ipsa_promcont'            => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'ipsa_status'              => new sfValidatorPass(array('required' => false)),
      'ipsa_regonline'           => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'entregas_myaltarget_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'EntregaMyaltarget', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('tbs_ip_salida_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addEntregasMyaltargetListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.EntregaMyaltargetIP EntregaMyaltargetIP')
      ->andWhereIn('EntregaMyaltargetIP.entregamyaltarget_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'TbsIpSalida';
  }

  public function getFields()
  {
    return array(
      'ipsa_codigo'              => 'Number',
      'ipsa_ip'                  => 'Text',
      'ipsa_nombre'              => 'Text',
      'ipsa_promcont'            => 'Number',
      'ipsa_status'              => 'Text',
      'ipsa_regonline'           => 'Boolean',
      'entregas_myaltarget_list' => 'ManyKey',
    );
  }
}
